const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack-dev-config.js');
const webpack = require('webpack');
const path = require('path');
const compiler = webpack(config);

const port = 8071;
const server = new WebpackDevServer(compiler, {
    contentBase: path.resolve(__dirname, './dist'), //默认会以根文件夹提供本地服务器，这里指定文件夹
    inline: true, // 自动刷新
    hot: true, // 开启热模块替换
    historyApiFallback: true, //在开发单页应用时非常有用，它依赖于HTML5 history API，如果设置为true，所有的跳转将指向index.html
    host: "localhost",
    port: port, //如果省略，默认8080
    proxy: {
        "*": {
            target: 'http://192.168.1.83:8098', // 内网服务器
            changeOrigin: true,
            bypass: function (req, res, proxyOptions) {
                if (req.headers.accept.indexOf('html') !== -1) {
                    console.log('Skipping proxy for browser request.');
                    return '/index.html';
                }
            }
        }
    },
    publicPath: "/"
});
server.listen(port, 'localhost', function (err) {
    if (err) throw err
});